package com.soilflow.info.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soilflow.common.core.domain.entity.SysUser;
import com.soilflow.common.domain.DahuBusiness;
import com.soilflow.common.domain.DahuJobhunt;
import com.soilflow.common.utils.DateUtils;
import com.soilflow.common.utils.SecurityUtils;
import com.soilflow.info.mapper.DahuJobhuntMapper;
import com.soilflow.info.service.IDahuJobhuntService;
import com.soilflow.system.mapper.DahuBusinessMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author party
 * @date 2023-11-02
 */
@Service
public class DahuJobhuntServiceImpl extends ServiceImpl<DahuJobhuntMapper, DahuJobhunt> implements IDahuJobhuntService {
    @Resource
    private DahuJobhuntMapper dahuJobhuntMapper;
    @Resource
    private DahuBusinessMapper dahuBusinessMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public DahuJobhunt selectDahuJobhuntById(Long id)
    {
        return dahuJobhuntMapper.selectDahuJobhuntById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param dahuJobhunt 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<DahuJobhunt> selectDahuJobhuntList(DahuJobhunt dahuJobhunt) {
        List<DahuJobhunt> dahuJobhunts = dahuJobhuntMapper.selectDahuJobhuntList(dahuJobhunt);
        for (DahuJobhunt jobhunt : dahuJobhunts) {
            Long createId = jobhunt.getCreateId();
            DahuBusiness dahuBusiness = dahuBusinessMapper.selectById(createId);
            jobhunt.setDahuBusiness(dahuBusiness);
        }
        return dahuJobhunts;
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param dahuJobhunt 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertDahuJobhunt(DahuJobhunt dahuJobhunt) {
        System.out.println("dahuJobhunt = " + dahuJobhunt);
        dahuJobhunt.setCreateTime(DateUtils.getNowDate());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        System.out.println("user = " + user);
        dahuJobhunt.setCreateId(user.getUserId());
        dahuJobhunt.setCreateBy(user.getUserName());
        return dahuJobhuntMapper.insert(dahuJobhunt);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param dahuJobhunt 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateDahuJobhunt(DahuJobhunt dahuJobhunt)
    {
        dahuJobhunt.setUpdateTime(DateUtils.getNowDate());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        dahuJobhunt.setUpdateBy(user.getNickName());
        dahuJobhunt.setUpdateId(user.getUserId());
        System.out.println("dahuJobhunt = " + dahuJobhunt);
        return dahuJobhuntMapper.updateById(dahuJobhunt);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDahuJobhuntByIds(Long[] ids) {
        for (Long id : ids) {
            LambdaUpdateWrapper<DahuJobhunt> wrapper=new LambdaUpdateWrapper<>();
            wrapper.eq(DahuJobhunt::getId,id);
            wrapper.set(DahuJobhunt::getDeleted,1);
            int update = dahuJobhuntMapper.update(null, wrapper);
        }
        return 1;
//        return dahuJobhuntMapper.deleteDahuJobhuntByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteDahuJobhuntById(Long id) {
        return dahuJobhuntMapper.deleteDahuJobhuntById(id);
    }
}
